using System;
using System.Collections.Generic;
using System.Text;
using Objects;

namespace DAL
{
    public class DALKhachHang
    {

        public List<KhachHang> GetAllItem()
        {
            List<KhachHang> ListKhachHang = new List<KhachHang>();

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] {"@Status"};
            string[] vname = new string[] {Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("KhachHang_GetAllItem", sname, vname);
            KhachHang Item = new KhachHang();

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                System.Data.DataRow dr = ds.Tables[0].Rows[i];
                ListKhachHang.Add((Item.Populate(dr)));
            }
            return ListKhachHang;
        }


        public KhachHang GetMaxId()
        {
            

            clsDataAccess acc = new clsDataAccess();

            string[] sname = new string[] { "@Status" };
            string[] vname = new string[] { Common.Myconst.HOATDONG.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("KhachHang_GetMaxId", sname, vname);
            KhachHang Item = new KhachHang();

          
                System.Data.DataRow dr = ds.Tables[0].Rows[0];
              return Item.Populate(dr);
           
        }

        public KhachHang GetById(int Id)
        {
            clsDataAccess acc = new clsDataAccess();
            string[] sname = new string[] { "@Id" };
            string[] vname = new string[] { Id.ToString() };
            System.Data.DataSet ds = acc.CommandSelect("KhachHang_GetById", sname, vname);
            KhachHang Item = new KhachHang();

            System.Data.DataRow dr = ds.Tables[0].Rows[0];
            return Item.Populate(dr);
        }

       
        public int Insert(KhachHang Item)
        {
            clsDataAccess acc = new clsDataAccess();


            string[] sname = new string[] { "@Ten", "@GioiTinh", "@IdQuocTich", "@NgaySinh", "@CMND", "@NgayCap", "@IdTinhThanh", "@DiaChiThuongTru", "@DiaChiLienLac", "@Email", "@DienThoaiNha", "@DienThoaiDiDong", "@GhiChu", "@Status", "@SapXep" };
            string[] vname = new string[] { Item.Ten.ToString(), Item.GioiTinh.ToString(), Item.IdQuoctich.ToString(), Item.NgaySinh.ToString(),Item.CMND.ToString(), Item.NgayCap.ToString(),
                                                                Item.IdTinhThanh.ToString(), Item.DiaChiThuongTru.ToString(), Item.DiaChiLienLac.ToString(), Item.Email.ToString(), Item.DienThoaiNha.ToString(),Item.DienThoaiDiDong.ToString(), Item.GhiChu.Trim(), Common.Myconst.HOATDONG.ToString(), Item.SapXep.ToString()};
            return acc.InsertUpdateDetete("KhachHang_Insert", sname, vname);

        }


        public int Update(KhachHang Item)
        {
            clsDataAccess acc = new clsDataAccess();


            string[] sname = new string[] { "@Id", "@Ten", "@GioiTinh", "@IdQuocTich", "@NgaySinh", "@CMND", "@NgayCap", "@IdTinhThanh", "@DiaChiThuongTru", "@DiaChiLienLac", "@Email", "@DienThoaiNha", "@DienThoaiDiDong", "@GhiChu", "@Status", "@SapXep" };
            string[] vname = new string[] { Item.Id.ToString(),  Item.Ten.ToString(), Item.GioiTinh.ToString(), Item.IdQuoctich.ToString(), Item.NgaySinh.ToString(),Item.CMND.ToString(), Item.NgayCap.ToString(),
                                                                Item.IdTinhThanh.ToString(), Item.DiaChiThuongTru.ToString(), Item.DiaChiLienLac.ToString(), Item.Email.ToString(), Item.DienThoaiNha.ToString(),Item.DienThoaiDiDong.ToString(), Item.GhiChu.Trim(), Item.Status.ToString(), Item.SapXep.ToString()};
            return acc.InsertUpdateDetete("KhachHang_Update", sname, vname);

        }

        public int Delete(KhachHang Item)
        {
            clsDataAccess acc = new clsDataAccess();


            string[] sname = new string[] { "@Id" };
            string[] vname = new string[] { Item.Id.ToString()};
            return acc.InsertUpdateDetete("KhachHang_Delete", sname, vname);

        }
    }
}
